# Given a 2D array and a number of generations, compute n timesteps of Conway's Game of Life.
# The rules of the game are:
# Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
# Any live cell with more than three live neighbours dies, as if by overcrowding.
# Any live cell with two or three live neighbours lives on to the next generation.
# Any dead cell with exactly three live neighbours becomes a live cell.

import numpy as np
def get_generation(cells, generations):
    height, width = len(cells), len(cells[0])
    temp_cells = np.array([[1,1,1],
                          [1,0,1],
                          [1,1,1]])
    cells_array = np.insert(np.insert(cells,(0,height),1,axis=0),(0,width),1,axis=1)
    for i in range(generations):
        target_cells = [[1 for i in range(width)] for j in range(height)]
        for hei in range(height):
            for wid in range(width):
                mul_array = cells_array[hei:hei+3,wid:wid+3]
                num = sum(sum(temp_cells*mul_array))
                if (num == 5) or (cells[hei][wid]==0 and num == 6):
                    target_cells[hei][wid] = 0
        cells = target_cells
    return cells

arr = [[1,0,0],[0,1,1],[1,1,0]]

print(get_generation(arr, 1))